import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)
import vuexPersist from "vuex-persist";
export default new Vuex.Store({
  state: {
    wishData: [],
  },
  mutations: {
    wishDataFn(state, val) {
      if (state.wishData.length >= 6) {
        alert('只能添加6许愿卡')
        return
      } else {
        state.wishData.push(val);
      }
    },
    // 删除卡片
    remove(state, i) {
      state.wishData.splice(i, 1);
    },
    // 编辑按钮
    edit(state, value) {
      console.log(value);
      state.wishData.forEach(item => {
        if (item.id == value.id) {
          item.img = value.img
          item.wish = value.wish
          item.tapId = value.tapId
        }
      })
      console.log(state.wishData);
    }
  },
  actions: {},
  modules: {},
  plugins: [
    new vuexPersist({
      storage: window.localStorage,
    }).plugin,
  ],
})